package com.dlc.shop.multishop.controller;

import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.dlc.shop.bean.model.*;
import com.dlc.shop.bean.param.OrderParam;
import com.dlc.shop.common.response.ServerResponseEntity;
import com.dlc.shop.common.util.PageParam;
import com.dlc.shop.delivery.common.service.DeliveryOrderService;
import com.dlc.shop.delivery.common.service.OrderSelfStationService;
import com.dlc.shop.service.*;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import org.springframework.context.ApplicationContext;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

@RestController
@RequestMapping("/order/order/multishopFromChina")
@Tag(name = "订单接口")
@AllArgsConstructor
public class OrderMultishopFromChina {

    private final OrderService orderService;

    private final OrderItemService orderItemService;
    private final OrderVirtualInfoService orderVirtualInfoService;

    private final UserAddrOrderService userAddrOrderService;

    private final OrderExcelService orderExcelService;

    private final DeliveryOrderService deliveryOrderService;

    private final ApplicationContext applicationContext;

    private final OrderSelfStationService orderSelfStationService;

    private final PlatformAddrService platformAddrService;


    /*@GetMapping("/page")
    @Operation(summary = "分页获取订单列表" , description = "分页获取订单列表")
    // @PreAuthorize("@pms.hasPermission('order:order:page')")
    public ServerResponseEntity<IPage<Order>> pageMultishopFromChina(OrderParam orderParam, PageParam<Order> page) {
        //Long shopId = SecurityUtils.getShopUser().getShopId();
        //orderParam.setShopId(shopId);
      //  if (orderParam.getStatus() == 2){
      //      orderParam.setIsChinaDvy(0);
      //  }

        IPage<Order> orderPage = orderService.pageOrdersDetailByOrderParam(page, orderParam);
        return ServerResponseEntity.success(orderPage);
    }
*/

    /*@GetMapping("/orderInfo/{orderNumber}")
    @Operation(summary = "根据订单号获取订单信息" , description = "根据订单号获取订单信息")
    //@PreAuthorize("@pms.hasPermission('order:order:info')")
    public ServerResponseEntity<Order> multishopFromChinaOrderInfo(@PathVariable("orderNumber") String orderNumber) {
        Long shopId = orderService.getOrderByOrderNumber(orderNumber).getShopId();

        Order order = orderService.getOrderByOrderNumberAndShopId(orderNumber, shopId, true);
        List<OrderItem> orderItems = orderItemService.getOrderItemsByOrderNumber(orderNumber,true);
        order.setOrderItems(orderItems);
        //用户地址信息
        UserAddrOrder userAddrOrder = userAddrOrderService.getById(order.getAddrOrderId());
        order.setUserAddrOrder(userAddrOrder);
        List<PlatformAddr> list = platformAddrService.queryList();
        order.setPlatformAddrs(list);
        if(Objects.equals(order.getOrderMold(),1)){
            List<OrderVirtualInfo> orderVirtualInfos = orderVirtualInfoService.list(new LambdaQueryWrapper<OrderVirtualInfo>().eq(OrderVirtualInfo::getOrderNumber, orderNumber).eq(OrderVirtualInfo::getIsWriteOff, 0));
            List<String> codes = new ArrayList<>();
            if(CollectionUtil.isNotEmpty(orderVirtualInfos)){
                codes = orderVirtualInfos.stream().map(OrderVirtualInfo::getWriteOffCode).collect(Collectors.toList());
            }
            order.setWriteOffCodes(codes);
        }
        return ServerResponseEntity.success(order);
    }*/
}
